<?php
	require_once (dirname(__FILE__) . "/../../config.php");
	//加密算法MCRYPT_BLOWFISH
	define("ALGORITHM",MCRYPT_TWOFISH);
	//加密key
	define("ENCRYPT_KEY",'%UgBgVIZsJUrekYT@Ro5*um#%B9QY1');
	//加密模式
	define("MODE",MCRYPT_MODE_CBC);
	define("RAND",MCRYPT_RAND);
	define("IV",'Vl4++49AOAO3PJZt');
	if(isset($_GET['put']))
	{
	 $put=$_GET['put'];
	 //解密后的数据
	 $decoded_data=getDecryption($put);
	 //分隔开解密后的数据
	 $fgddata=array();
	 $fgddata=explode("|",$decoded_data);
	 outPutXml(insertFwversion($fgddata[0],$fgddata[1]));
	 //getEncryption($messagecontent);
	}

		
	//将传入的数据加到数据库中
	function insertFwversion($mac,$version_number){
		$sqlselect="select version_number from zy_fwversion where mac='$mac'";
		$rsselect=mysql_query($sqlselect);
		$row=mysql_fetch_array($rsselect);
		if(empty($row)){
		 $sqlinsert="insert into zy_fwversion(mac,version_number) values('$mac','$version_number')";
		 $rsinsert=mysql_query($sqlinsert);
		 //成功
		 if($rsinsert>0){
		    $outPutXml="<result>1</result>\n";
		    return $outPutXml;
		 }else{
		 	//失败
	    	$outPutXml="<result>0</result>\n";
		    return $outPutXml;
		 	  }
		}else{
			$sqlupdate="update zy_fwversion set version_number='$version_number' where mac='$mac'";
			$rsupdate=mysql_query($sqlupdate);
		 //成功
		 if($rsupdate>0){
	      	$outPutXml="<result>1</result>\n";
		    return $outPutXml;
		 }else{
		 	//失败
	    		$outPutXml="<result>0</result>\n";
				return $outPutXml;
		 }
		}
	}
	//加密数据
//	function getEncryption($data){
//		//加密data
//		$encrypted_data = mcrypt_encrypt ( ALGORITHM, ENCRYPT_KEY,$data, MODE,IV);
//		$plain_text = base64_encode ( $encrypted_data );
//		//打印加密后的data
//		echo urlencode($plain_text);
//	}
	
	//解密数据
	function getDecryption($data){
		$encrypted_data = base64_decode ( $data );
		//解密data
		$decoded = mcrypt_decrypt ( ALGORITHM, ENCRYPT_KEY, $encrypted_data, MODE,IV);
		//打印解密后的data
		return $decoded;
	}

    function outPutXml($content) {
	header("Content-type:text/xml");
	echo "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n";
	echo "<netcuberesult>\n";
	echo $content;
	echo "</netcuberesult>";
	die();
}
?>
